import time

import allure
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from src.PO.base import Base


@allure.feature("添加商品信息界面")
class ProductAddition(Base):
    __ID=(By.CSS_SELECTOR,".app-container>div:nth-child(1)>div>.el-form>div:nth-child(1)>div>div>.el-input__inner")
    __NAME=(By.CSS_SELECTOR,".app-container>div:nth-child(1)>div>.el-form>div:nth-child(2)>div>div>.el-input__inner")
    __PUT_ON_SHELVES=(By.XPATH, "//*[text()='上架']")
    __JUDGMENT=(By.XPATH,"//*[text()='黑神话悟空']")
    # def __init__(self,driver:WebDriver):
    #     self.driver=driver

    @allure.story("输入商品信息")
    def add_product(self):
        from src.PO.product_list_page import ProductListPage
        with allure.step("输入编号"):
            # self.driver.find_element(*self.__ID).send_keys("6699329")
            self.find_and_send(*self.__ID,text="6699329")
        with allure.step("输入名称"):
            # self.driver.find_element(*self.__NAME).send_keys("黑神话悟空")
            self.find_and_send(*self.__NAME,text="黑神话悟空")
        with allure.step("点击上架,跳转商品列表界面"):
            shelves = self.find(*self.__PUT_ON_SHELVES)
            ActionChains(self.driver).scroll_to_element(shelves).perform()  # 滚动鼠标
            shelves.click()
            WebDriverWait(self.driver,10).until(expected_conditions.visibility_of_element_located((self.__JUDGMENT)))
        return ProductListPage(self.driver)

